clear
use "workingdirectoryhere\Knutsen_Wig_CPS_final.dta", clear

*****THIS CODE REPLICATES THE FIRST STEP OF THE CREATION OF FIGURE 2 IN KNUTSEN AND WIG 2014 (to re-create FIGURE 2 with the expansive real-time DD coding, run this code with dem_realtimeDD2 replaced by dem_realtimeDD)
*****Running the models for different time periods and saving the estimates

***********************************************************
******************** Picking up the data ******************
***********************************************************

***BASELINE DD - ESTIMATING THE BASELINE MODEL WITH PCSEs for each year and Saving coefficients and SEs in the dataset
xtset gwno year

gen coefficientDD = .
gen sesDD = .
foreach i of num 1960/2008 {
quietly xtpcse lead5growthgdppc_Mad democracy logGDPpc_Mad logpop_Mad ethnfrac easteursov africass asiapac mideanafr latam _19*, correlation(psar1) rhotype(tscorr) pairwise , if year <= `i'
replace coefficientDD = _b[democracy]  if year==`i'
replace sesDD = _se[democracy] if year==`i'

}


***REAL TIME DD - ESTIMATING THE BASELINE MODEL WITH PCSEs for each year and Saving coefficients and ses in the dataset
gen coefficientRT = .
gen sesRT = .
foreach i of num 1960/2008 {
quietly xtpcse lead5growthgdppc_Mad dem_realtimeDD2 logGDPpc_Mad logpop_Mad ethnfrac easteursov africass asiapac mideanafr latam _19*, correlation(psar1) rhotype(tscorr) pairwise , if year <= `i'
replace coefficientRT = _b[dem_realtimeDD2]  if year==`i'
replace sesRT = _se[dem_realtimeDD2] if year==`i'
}


export delimited using "workingdirectoryhere\graphdata.csv", replace
